/*
 * Copyright (c) 2010 Nokia Corporation.
 */

#include "keyeventlistener.h"

KeyEventListener::KeyEventListener(QObject *parent) :
    QObject(parent)
{
}

KeyEventListener::~KeyEventListener()
{
}

bool KeyEventListener::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::KeyPress) {
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
        if (keyEvent->key()==16777385) {
            emit keyboardEnabled(); // User opens keyboard (Nokia E7)
        } else if (keyEvent->key()==16777386) {
            emit keyboardDisabled(); // User closes keyboard (Nokia E7)
        } else {
            emit keyboardEnabled(); // User uses keyboard
        }
        return false;
    } else if (event->type() == QEvent::MouseButtonPress) {
        emit keyboardDisabled(); // User touch the screen
        return false;
    } else {
        // standard event processing
        return QObject::eventFilter(obj, event);
    }
}
